package pl.matt.media.procesor.impl;

import java.io.File;
import java.io.IOException;

import pl.matt.media.manager.ImageManager;
import pl.matt.media.manager.MediaManagersFactory;
import pl.matt.media.model.ImageType;
import pl.matt.media.procesor.FrameProcessor;

public class RectangleCutFrameProcessor implements FrameProcessor {

	private ImageManager imageManager = MediaManagersFactory.getImageManager();
	private String destinationImageFileName;
	int widthPercentage;
	int heightPercentage;
	int xPercentage;
	int yPercentage;
	
	public static void main(String[] args) {
		new RectangleCutFrameProcessor("1", 2, 4, 3, 5);
	}
	
	public RectangleCutFrameProcessor(String destinationImageFileName, int xPercentage, int yPercentage, int widthPercentage, int heightPercentage) {
		this.destinationImageFileName = destinationImageFileName;
		this.yPercentage = yPercentage;
		this.xPercentage = xPercentage;
		this.widthPercentage = widthPercentage;
		this.heightPercentage = heightPercentage;
	}
	
	@Override
	public void processFrame(String sourceImagePath) throws IOException {
		String destinationImagePath = sourceImagePath.substring(0, sourceImagePath.lastIndexOf(File.separatorChar) + 1) + destinationImageFileName;
		imageManager.cropImageWithPercentageDimensions(sourceImagePath, destinationImagePath, xPercentage, yPercentage, widthPercentage, heightPercentage, ImageType.JPEG);		
	}

}
